#include <zstack/queue.h>
#include <string.h>

U32 queue_push(struct queue *q, U32 item)
{
	U32 count;
	U32 index;

	count = q->wr - q->rd;
	
	if (count >= q->size)
		return 0;

	index = q->wr % q->size;

	q->buf[index] = item;

	q->wr++;
	
	return 1;
}

U32 queue_pop(struct queue *q, U32 *item)
{
	U32 count;
	U32 index;

	count = q->wr - q->rd;
	
	if (0 == count)
		return 0;
	
	index = q->rd % q->size;

	*item = q->buf[index];

	q->rd++;
	
	return 1;
}

